package cn.kgc.hotel.controller;

import cn.kgc.hotel.entity.Param.UserParam;
import cn.kgc.hotel.entity.ReturnResultMessage;
import cn.kgc.hotel.entity.User;
import cn.kgc.hotel.service.UserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserController {

    @Resource UserService userService;

    @RequestMapping("/showUser")
    public ReturnResultMessage showUser(UserParam userShowParam){
        ReturnResultMessage returnResultMessage = new ReturnResultMessage();
        List<User> users = userService.showUser(userShowParam);

        returnResultMessage.setCode("success");
        returnResultMessage.setMsg("成功");
        returnResultMessage.setData(users);

        return returnResultMessage;
    }


    @RequestMapping("/addUser")
    public ReturnResultMessage addUser(UserParam userParam){
        ReturnResultMessage returnResultMessage = new ReturnResultMessage();
        boolean flag = userService.addUser(userParam);
        if (flag) {
            returnResultMessage.setCode("success");
            returnResultMessage.setMsg("用户添加成功");
        } else {
            returnResultMessage.setCode("error");
            returnResultMessage.setMsg("用户添加失败");
        }
        return returnResultMessage;
    }

    @RequestMapping("/updateUser")
    public ReturnResultMessage updateUser(UserParam userParam){
        ReturnResultMessage returnResultMessage = new ReturnResultMessage();
        boolean flag = userService.updateUser(userParam);
        if (flag) {
            returnResultMessage.setCode("success");
            returnResultMessage.setMsg("用户修改成功");
        } else {
            returnResultMessage.setCode("error");
            returnResultMessage.setMsg("用户修改失败");
        }
        return returnResultMessage;
    }

    @RequestMapping("/deleteUser")
    public ReturnResultMessage deleteUser(UserParam userParam){
        ReturnResultMessage returnResultMessage = new ReturnResultMessage();
        boolean flag = userService.deleteUser(userParam);
        if (flag) {
            returnResultMessage.setCode("success");
            returnResultMessage.setMsg("用户删除成功");
        } else {
            returnResultMessage.setCode("error");
            returnResultMessage.setMsg("用户删除失败");
        }
        return returnResultMessage;
    }
}
